import time

import allure

from src.main.page.login_page import Login_page

'''
pytest -vs  .\src\test\it\po_qiye_weixin_test.py::Test_qiyeweixin::test_add_member_and_remove --alluredir allure_results


allure serve ./allure_results

'''

class Test_qiyeweixin:

    @allure.title('企业微信的cookie登录用例')
    def test_login(self,my_fixture):
        login = my_fixture
        login.login()
        pass

    @allure.title('企业微信添加成员')
    def test_add_member(self,my_fixture):
        login = Login_page()
        main_page = login.login()
        contact_page = main_page.goto_contact()

        add_member_page = contact_page.goto_add_member_page()

        newer_name = add_member_page.add_member()[0]
        pass


    @allure.title('企业微信添加成员后找到并删除成员')
    def test_add_member_and_remove(self,my_fixture):
        login = my_fixture
        main_page = login.login()
        main_page.screen_shot()
        contact_page = main_page.goto_contact()

        time.sleep(2)
        contact_page.screen_shot()
        add_member_page = contact_page.goto_add_member_page()

        time.sleep(2)
        newer_name,phone = add_member_page.add_member()
        time.sleep(2)
        member_list = contact_page.get_member_list()

        member_list_phone = contact_page.get_member_list_phone()
        time.sleep(2)
        name_list = []
        phone_list = []
        for index, i in enumerate(member_list_phone):
            phone_list.append(i.text)
        assert phone in phone_list



        for index, i in enumerate(member_list):
            name_list.append(i.text)

        assert newer_name in name_list


        for index, i in enumerate(member_list):

            if i.text == newer_name:
                contact_page.delete_member_single(index)
                break

        time.sleep(2)
        pass

    @allure.title('企业微信添加子部门')
    def test_add_department(self,my_fixture):
        login = my_fixture
        main_page = login.login()
        contact_page = main_page.goto_contact()
        contact_page.click_deparkment_btn_add_department()
        pass


    @allure.title('企业微信添加子部门后往这个子部门里添加成员然后删除子部门,及其成员')
    def test_add_department_and_add_member_delete(self,my_fixture):
        login = my_fixture
        main_page = login.login()
        contact_page = main_page.goto_contact()
        contact_page.click_deparkment_btn_add_department()

        add_member_page=contact_page.add_member_after_add_department()

        name = add_member_page.add_member()[0]


        member_list = contact_page.get_member_list()

        for index, i in enumerate(member_list):

            if i.text == name:
                contact_page.delete_member_single(index)
                break

        contact_page.delete_department()
        pass

    @allure.title('企业微信检验添加成员时必填字段为空时的报错')
    def test_delete_department(self,my_fixture):
        login = my_fixture
        main_page = login.login()
        contact_page = main_page.goto_contact()
        add_member_page=contact_page.goto_add_member_page()
        add_member_page.check_input_is_empty()



